package com.colin.aiyi.dao.ImpxUtils;

import com.colin.aiyi.app.Constant;
import com.colin.aiyi.entity.response.BaseResponse;
import com.colin.aiyi.entity.User;

import org.xutils.http.RequestParams;

import java.io.File;

/**
 * Created by hl on 2017/6/9.
 */

public class ImpSaveUserInfo extends AbsServicexUtils{
    @Override
    public void onSuccess(String result) {
        super.onSuccess(result);
        if (callback==null)
        {
            sendMsgToView(BaseResponse.class,result);
        }else {
            BaseResponse loginResponse=gson.fromJson(result,BaseResponse.class);
            callback.onSuccess(loginResponse);
        }
    }

    @Override
    public <V> void getObject(V v) {
        super.getObject(v);
        User user= (User) v;
        RequestParams parems=new RequestParams(Constant.saveUserInfo);
        parems.addBodyParameter("clientId",Constant.CLIENT_ID);
        parems.addBodyParameter("accessToken", user.getAccessToken());
        parems.addBodyParameter("clientSecret",Constant.CLIENT_SECRET);
        if ( user.getUserName()!=null){
            parems.addBodyParameter("userName",user.getUserName());
        }
        if ( user.getBirthbay()!=0){
            parems.addBodyParameter("birthbay", user.getBirthbay()+"");
        }
        if ( user.getSex()!=0){
            parems.addBodyParameter("sex", user.getSex()+"");
        }
        parems.addBodyParameter("isListen", String.valueOf( user.isListen()));
        parems.addBodyParameter("isPush", String.valueOf( user.isPush()));
        if ( user.getCityId()!=null){
            parems.addBodyParameter("cityId", user.getCityId());
        }
        if ( user.getConstellation()!=null){
            parems.addBodyParameter("constellation", user.getConstellation());
        }
        if ( user.getHeadUrl_local()!=null)
        {
            parems.setMultipart(true);
            //  上传文件方式 1
            //  params.uploadFile = new File("/sdcard/test.txt");
            //   上传文件方式 2
            parems.addBodyParameter("imgFile", new File( user.getHeadUrl_local()));
        }

        sendToServer(parems,1);
        }
    }
